//
// Created by Administrator on 2021/9/28.
//

#include "Log.h"

void Log::printlog(LogLevel level, const char *fmt, ...) {
    const char* LEVEL = "INFO";
    switch (level) {
        case LogLevel::DEBUG:
            LEVEL = "DEBUG";
            break;
        case LogLevel::INFO:
            LEVEL = "INFO";
            break;
        case LogLevel::WARN:
            LEVEL = "WARN";
            break;
        case LogLevel::ERR:
            LEVEL = "ERROR";
            break;
    }

    char msg[MSG_LENGTH];
    va_list arg;
    va_start(arg, fmt);
    _vsnprintf(msg, MSG_LENGTH, fmt, arg);
    va_end(arg);

    static struct tm tt;

    _getsystime(&tt);
    printf("%d-%d-%d %d:%0.2d:%0.2d [%s] %s\n", 1900 + tt.tm_year, 1 + tt.tm_mon,tt.tm_mday,tt.tm_hour,tt.tm_min, tt.tm_sec, LEVEL, msg);

    fflush(stdout);
}


